package com.ostrich.system.analysis;

import java.util.LinkedHashMap;
import java.lang.Float;
import java.math.BigDecimal;

public class FormulaAnalysis {

	/***
	 * 求和的方法
	 * 
	 * @param A
	 * @return
	 */
	public static Float getSum(Object[] A) {
		if (A != null) {
			Float sum = new Float(0);
			for (Object obj : A) {
				if (obj != null) {
					Float obja = Float.valueOf(obj.toString());
					sum += obja;
				}
			}
			BigDecimal b = new BigDecimal(sum); 
			float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); 
			return f1;
		}
		return new Float(0);
	}

	/****
	 * 求乘积的方法
	 * 
	 * @param A
	 * @return
	 */
	public static Float getMultiplication(Object[] A) {
		if (A != null) {
			Float mu = new Float(1);
			for (Object obj : A) {
				if (obj != null) {
					Float obja = Float.valueOf(obj.toString());
					mu = mu * obja;
				}
			}
			BigDecimal b = new BigDecimal(mu); 
			float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); 
			return f1;
		}
		return new Float(0);
	}

	/****
	 * 求平均值的方法
	 * 
	 * @param A
	 * @return
	 */
	public static Float getAverage(Object[] A) {
		if (A != null) {
			Float avg = getSum(A) / A.length;
			BigDecimal b = new BigDecimal(avg); 
			float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); 
			return f1;
		}
		return new Float(0);
	}
	
	
	public static LinkedHashMap<String,Object> getScale(){
		
		return null;
	}
	
	public static void main(String[] args) {
		Object[] a = {new Float(1),new Float(1),new Float(1)};
		System.out.println(new FormulaAnalysis().getSum(a));
	}

}
